473,425 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

HTML Select option selected color style

Is there a style for a select option's "selected" color? For example:

<HTML>
<BODY>
<FORM NAME="form1">
<SELECT NAME="mySelect" SIZE="7" style="background-color:red;">
<OPTION>Test 1
<OPTION>Test 2
<OPTION>Test 3
<OPTION>Test 4
<OPTION>Test 5
<OPTION>Test 6
<OPTION>Test 7
</SELECT>
</FORM>
</BODY>
</HTML>

When I select an option it turns blue, I want to override this and
make it a different color. In the style I expected something like
"selected-color", but it doesn't exist. I've also tried using
javascript to change the background color (works if I click on a
different option using the onClick event
mySelect.option[2].style.backgroundColor="green"), but something seems
to be overriding it if I click on the option I want to change). Here's
the code for that option that I've been playing with:

<HTML>
<HEAD>
<TITLE>

</TITLE>
<SCRIPT>
function init() {
document.formName.selectName.options[5].style.backgroundColor
='green';
document.formName.selectName.options[5].style.color ='red';
document.formName.selectName.options[5].style.foregroundColor
='orange';
document.formName.selectName.options[5].style.bgColor ='red';
}
function test(tst) {
alert(tst);
document.formName.selectName.options[5].style.backgroundColor
='black';
document.formName.selectName.options[5].style.color ='black';
document.formName.selectName.options[5].style.foregroundColor
='black';
document.formName.selectName.options[5].style.bgColor ='black';
}
</SCRIPT>
</HEAD>
<BODY ONLOAD="init();">
<FORM NAME="formName">
<SELECT NAME="selectName" style="background-color:red" SIZE="7"
onclick="window.event.cancelBubble='true';test('on click')">
<OPTION>TEST 1
<OPTION>TEST 2
<OPTION>TEST 3
<OPTION>TEST 4
<OPTION>TEST 5
<OPTION>TEST 6
<OPTION>TEST 7
</SELECT>
</FORM>
</BODY>
</HTML>

Any ideas appreciated!

Thanks!
Jeff
Jul 20 '05 #1
4 102916
jc********@statestreetkc.com (Jeff Anderson) wrote:
Is there a style for a select option's "selected" color?


You could try option:focus {} but I doubt you'd have much luck and it
certainly wouldn't work in IE.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #2
Steve Pugh <st***@pugh.net> wrote:
jc********@statestreetkc.com (Jeff Anderson) wrote:
Is there a style for a select option's "selected" color?


You could try option:focus {} but I doubt you'd have much luck and it
certainly wouldn't work in IE.


I should have added that CSS3 has the :checked pseudo-class will be
the proper way of doing this. At least I think so, it may or may not
apply here (the examples given are of radio buttons and checkboxes;
but the mention of the HTML selected attribute can be taken as
including option elements, as they're the only element that attribute
exists for).

However, I know of no browser that supports this part of CSS3 yet.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #3
Steve Pugh <st***@pugh.net> wrote:
Is there a style for a select option's "selected" color?


You could try option:focus {} but I doubt you'd have much luck and it
certainly wouldn't work in IE.


The :focus pseudo-class is confusingly defined in the specification and
inconsistently implemented in vrowsers. But I think it is certainly not
meant to be identical with the concept of 'selected option' when used
for an option element. When you have selected an option from a
select menu and then move to another field, by tabbing or clicking for
example, then surely the focus moves away from the select or option
element, if it was there.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Jul 20 '05 #4
Steve Pugh wrote:
However, I know of no browser that supports this part of CSS3 yet.


Mozilla: <http://bugzilla.mozilla.org/show_bug.cgi?id=120834>
--
Anne van Kesteren
<http://www.annevankesteren.nl/>
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bruce | last post by:
For those of you using templates to keep your PHP and HTML code separate..... How do you handle a HTML Select statement when the initial option selected needs to come from a database field? ...
2
by: Targa | last post by:
I have a select box with about 5 options. I need to have one of the options, when selected, display a second select box. The second select box is populated by a database and needs to be preloaded...
3
by: Oeivind | last post by:
Hi at all ! When I select an option or the SELECT item gets focus, it turns blue, I want to override this and make it a different color. Is there some cure for this ? Oivind
3
by: ANTISPAM_garycnew_ANTISPAM | last post by:
What is the simplest way to retain the last option value selected in an html select object using javascript? I am currently using a server-side cgi language to accomplish this task, but it adds...
6
by: artev | last post by:
if I have a select with more options, how I can know if is there an option selected; is necessary a cycle? or is there an inner property?
1
by: empiresolutions | last post by:
I have a page where the <select> is very screen right. it has little room to show the full name in the <option> so i do like "S - Summary". You only end up seen the S. When the dropdown happens, my...
2
by: Problematic coder | last post by:
I have a need in an application to have the ability to select multiple values in some kind of drop down list or maybe even a html type select box. I have found there doesn't seem to be an option...
7
by: fsalvador | last post by:
Hi, I am trying to figure it out how to to hide in onmouseout the select options of a form. Below is the code I got so far. It isn't working. Please help. Thanks <!DOCTYPE HTML PUBLIC...
2
by: saurabh moses | last post by:
hi can anybody help me on <select> option in website I have multiple option bar with multiple choices i want when i select one choice in one bar it show only related choices on another option bar....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.